package csc411;

public class Account {

	private int accountNum;
	private String name;
	private String password;
	private Currency type;
	private float balance;

	public Account(int accountNum, String name, String password,
			Currency type, float initAmount) {

		this.accountNum = accountNum;
		this.name = name;
		this.password = password;
		this.type = type;
		this.balance = initAmount;

	}

	public int getAccountNum() {
		return this.accountNum;
	}

	public String getName() {
		return this.name;
	}

	public String getPassword() {
		return this.password;
	}

	public Currency getType() {
		return this.type;
	}

	public float getBalance() {
		return this.balance;
	}

	public void deposit(Currency type, float amount) throws Exception {

		if (amount <= 0) {
			throw new Exception("Invalid deposit amount (" + amount + ")");
		}

		if (type != this.type) {
			amount = Rates.convert(amount, type, this.type);
		}

		this.balance = balance + amount;
	}

	public void withdraw(Currency type, float amount) throws Exception {

		// Note: amount for withdraw are negative in value
		if (amount >= 0) {
			throw new Exception("Invalid deposit withdraw------ (" + amount + ")");
		}

		if (type != this.type) {
			amount = Rates.convert(amount, type, this.type);
		}

		if (this.balance + amount < 0) {
			throw new Exception("Insufficient balance");
		}

		this.balance = this.balance + amount;
	}

	public String getBalanceString() {
		return Utils.printMoney(this.type, this.balance);
	}
}
